package com.lijiajian.controller;

import com.lijiajian.Service.CusDevPlanService;
import com.lijiajian.Service.SaleChanceService;
import com.lijiajian.annoation.RequiredPermission;
import com.lijiajian.base.BaseController;
import com.lijiajian.base.ResultInfo;
import com.lijiajian.pojo.CusDevPlan;
import com.lijiajian.pojo.SaleChance;
import com.lijiajian.query.CusDevPlanQuery;
import com.lijiajian.query.SaleChanceQuery;
import com.lijiajian.utils.LoginUserUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("cusDevPlan")
public class CusDevPlanController extends BaseController {
    @Resource
    private SaleChanceService saleChanceService;
    @Resource
    private CusDevPlanService cusDevPlanService;

    @RequiredPermission(code="1020")
    @GetMapping("index")
    public String index(){
        return "cusDevPlan/cusDevPlan";
    }

    /**
     * 前往计划项数据页面
     * @param id
     * @param request
     * @return
     */
    @RequestMapping("toCusDevPlan")
    public String toCusDevPlan(Integer id, HttpServletRequest request){
        SaleChance saleChance = saleChanceService.selectByPrimaryKey(id);
        request.setAttribute("saleChance",saleChance);
        return "cusDevPlan/cusDevPlanData";

    }
    @RequiredPermission(code="102001")
    @GetMapping("cusDevPlanList")
    @ResponseBody
    public Map<String,Object> queryCusDevPlanByParams(CusDevPlanQuery cusDevPlanQuery){
        return cusDevPlanService.queryCusDevPlanByParams(cusDevPlanQuery);
    }
    @PostMapping("add")
    @ResponseBody
    public ResultInfo addCusDevPlan(CusDevPlan cusDevPlan){
        cusDevPlanService.addCusDevPlan(cusDevPlan);
        return success("计划项添加成功");
    }

    /**
     * 前往添加或修改页面
     * @return
     */
    @GetMapping("toAddAndUpdatePage")
    public String toAddAndUpdatePage(Integer saleChanceId,HttpServletRequest request,Integer id){
        request.setAttribute("saleChanceId",saleChanceId);
        if(id!=null){
            CusDevPlan cusDevPlan = cusDevPlanService.selectByPrimaryKey(id);
            request.setAttribute("cusDevPlan",cusDevPlan);
        }

        return "cusDevPlan/addAndUpdate";

    }

    /**
     * 修改客户开发计划
     * @param cusDevPlan
     * @return
     */
    @PostMapping("update")
    @ResponseBody
    public ResultInfo update(CusDevPlan cusDevPlan){
        cusDevPlanService.updateCusDevPlan(cusDevPlan);
        return success("计划项更新成功");
    }
    /**
     * 删除客户开发计划
     * @param id
     * @return
     */
    @PostMapping("delete")
    @ResponseBody
    public ResultInfo delete(Integer id){
        cusDevPlanService.deleteCusDevPlan(id);
        return success("计划项删除成功");
    }

    /**
     * 更新营销机会开发状态
     * @param id
     * @return
     */
    @PostMapping("updateSaleChanceDevResult")
    @ResponseBody
    public ResultInfo updateSaleChanceDevResult(Integer id,Integer devResult){
        saleChanceService.updateSaleChanceDevResult(id,devResult);
        return success("营销机会开发状态修改成功");
    }





}
